import VisClassOrInterfaceNode from "@/types/VisClassOrInterfaceNode";
import React from "react";
import NodeBox from "../NodeBox";
import MethodNode from "../MethodNode";
import FieldNode from "../FieldNode";
import TopLevelNode from "./TopLevelNode";
import ConstructorNode from "../ConstructorNode";

export default function CLassOrInterfaceNode(props: {
  coiNode: VisClassOrInterfaceNode;
}) {
  const { coiNode } = props;
  return (
    <NodeBox
      range={coiNode.range}
      displayName={coiNode.identifier}
      color="#3949AB"
      icon={
        coiNode.isInterface ? (
          <span className="iconfont icon-add" />
        ) : (
          <span className="iconfont icon-class" />
        )
      }
    >
      {coiNode.methods.map((m) => (
        <MethodNode methodNode={m} key={m.body} />
      ))}
      {coiNode.constructors.map((c) => (
        <ConstructorNode constructorNode={c} key={c.body} />
      ))}
      {coiNode.fields.map((f) => (
        <FieldNode fieldNode={f} key={f.identifier} />
      ))}
      {coiNode.classOrInterfaces?.map((topLevel) => {
        return (
          <TopLevelNode node={topLevel} key={JSON.stringify(topLevel.range)} />
        );
      })}
      {coiNode.enums?.map((topLevel) => {
        return (
          <TopLevelNode node={topLevel} key={JSON.stringify(topLevel.range)} />
        );
      })}
    </NodeBox>
  );
}
